﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PDE
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            textBox1.Text = "0,01";
            textBox2.Text = "1e-6";
            textBox3.Text = "30";
            textBox4.Text = "1";

            textBox5.Text = "0,01";
            textBox6.Text = "1e-6";
            textBox7.Text = "30";
            textBox8.Text = "1";
            textBox13.Text = "1";

            textBox9.Text = "0,01";
            textBox11.Text = "1e-6";
            textBox10.Text = "30";
            textBox12.Text = "1";
            textBox14.Text = "1";
            textBox15.Text = "1";
            textBox16.Text = "1";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double h0;
            double.TryParse(textBox1.Text, out h0);

            double eps;
            double.TryParse(textBox2.Text, out eps);

            int maxStep;
            int.TryParse(textBox3.Text, out maxStep);

            double u0;
            double.TryParse(textBox4.Text, out u0);

            PdeTest solver = new PdeTest(h0, eps, u0, maxStep);
            solver.Test();

            double t = 0;

            chart1.Series.Clear();
            chart1.Series.Add("u");
            chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            chart2.Series.Clear();
            chart2.Series.Add("s");
            chart2.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            chart3.Series.Clear();
            chart3.Series.Add("h");
            chart3.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            double epsmin = eps/Math.Pow(2.0,5);
            dataGridView1.Rows.Clear();
            for (int i = 1; i <= maxStep; i++)
            {
                chart1.Series[0].Points.AddXY(t, solver.u[i]);
                chart2.Series[0].Points.AddXY(i, solver.s[i-1]);
                chart3.Series[0].Points.AddXY(i, solver.h[i-1]);
 
                t = t + solver.h[i-1];
                dataGridView1.Rows.Add(
                    t,
                    solver.u[i],
                    solver.s[i - 1],
                    epsmin,
                    solver.h[i - 1],
                    solver.c1[i],
                    solver.c2[i],
                    solver.reu(t),
                    Math.Abs(solver.u[i] - solver.reu(t))
                    );
                    
            }

            


            


        }

        private void button2_Click(object sender, EventArgs e)
        {
            double h0;
            double.TryParse(textBox5.Text, out h0);

            double eps;
            double.TryParse(textBox6.Text, out eps);

            int maxStep;
            int.TryParse(textBox7.Text, out maxStep);

            double u0;
            double.TryParse(textBox8.Text, out u0);

            double x0;
            double.TryParse(textBox13.Text, out x0);

            

            PdeTask1 solver = new PdeTask1(h0, eps, u0, maxStep,x0);
            solver.Task1();

            

            chart4.Series.Clear();
            chart4.Series.Add("u");
            chart4.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            chart5.Series.Clear();
            chart5.Series.Add("s");
            chart5.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            chart6.Series.Clear();
            chart6.Series.Add("h");
            chart6.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            double epsmin = eps / Math.Pow(2.0, 5);
            dataGridView2.Rows.Clear();
            for (int i = 1; i <= maxStep; i++)
            {
                chart4.Series[0].Points.AddXY(solver.x[i], solver.u[i]);
                chart5.Series[0].Points.AddXY(i, solver.s[i - 1]);
                chart6.Series[0].Points.AddXY(i, solver.h[i - 1]);

                
                dataGridView2.Rows.Add(
                    solver.x[i],
                    solver.u[i],
                    solver.s[i - 1],
                    epsmin,
                    solver.h[i - 1],
                    solver.c1[i],
                    solver.c2[i]
                    );

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            double h0;
            double.TryParse(textBox9.Text, out h0);

            double eps;
            double.TryParse(textBox11.Text, out eps);

            int maxStep;
            int.TryParse(textBox10.Text, out maxStep);

            double u0;
            double.TryParse(textBox12.Text, out u0);

            double x0;
            double.TryParse(textBox15.Text, out x0);

            double v0;
            double.TryParse(textBox14.Text, out v0);

            double a;
            double.TryParse(textBox16.Text, out a);

            PdeTask2 solver = new PdeTask2(h0, eps, u0, v0, maxStep, x0);
            solver.Task2(a);

            chart7.Series.Clear();
            chart7.Series.Add("u, u'");
            chart7.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            chart8.Series.Clear();
            chart8.Series.Add("u");
            chart8.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            chart9.Series.Clear();
            chart9.Series.Add("u'");
            chart9.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            double epsmin = eps / Math.Pow(2.0, 5);
            dataGridView3.Rows.Clear();
            for (int i = 1; i <= maxStep; i++)
            {
                chart7.Series[0].Points.AddXY(solver.u[i,0], solver.u[i,1]);
                chart8.Series[0].Points.AddXY(solver.x[i], solver.u[i,0]);
                chart9.Series[0].Points.AddXY(solver.x[i], solver.u[i,1]);


                dataGridView3.Rows.Add(
                    solver.x[i],
                    solver.s[i - 1],
                    epsmin,
                    solver.h[i - 1],
                    solver.c1[i],
                    solver.c2[i]
                    );

            }

        }
    }
}
